'''
* This is the projet for Brtc LlmOps Platform
* @Author Leon-liao <liaosiliang@alltman.com>
* @Description //TODO 
* @File: upload_file_handler.py
* @Time: 2025/11/12
* @All Rights Reserve By Brtc
'''
from dataclasses import dataclass

from injector import inject

from internal.schema.upload_file_schema import UploadFileReq, UploadFileResp
from internal.service import CosService
from pkg.response.response import validate_error_json, success_json


@inject
@dataclass
class UploadFileHandler:
    """上传文件处理器"""
    cos_service:CosService


    def upload_file(self):
        """上传文件/文档"""
        #1、构建请求并校验
        req = UploadFileReq()
        if not req.validate():
            return validate_error_json(req.errors)
        #2、调用服务上传文件并获取记录
        upload_file = self.cos_service.upload_file(req.file.data)
        #3、构建响应并返回
        resp = UploadFileResp()
        return success_json(resp.dump(upload_file))